package com.demo.controller;

import com.demo.bean.User;
import com.demo.service.RedisService;
import com.demo.servicelmpl.DeleteWrongData;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.LinkedHashMap;
import java.util.Objects;

/**
 * @author 李天航
 * 帮助开启一些功能的线程，只有admin能进来
 */
@RestController
@RequestMapping("/admin")
public class HelpStartController {
    @Resource
    DeleteWrongData deleteWrongData;
    @Resource
    RedisService redisService;

    final String ADMINACCOUNT="admin";

    @PostMapping("/deletewrongdata")
    Object deleteWrongData(HttpSession session)
    {
        User user=(User) redisService.getSessionData(session.getId(),"user");
        LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
        if(!Objects.equals(user.getUserAccount(), ADMINACCOUNT))
        {
            resultMap.put("msg","禁止访问");
            return resultMap;
        }
        deleteWrongData.start();
        resultMap.put("msg","线程停止");
        return resultMap;
    }
}
